package icu.d4peng.basic.captcha;

import com.wf.captcha.base.Captcha;
import icu.d4peng.basic.captcha.properties.CaptchaProperties;
import icu.d4peng.basic.captcha.service.CaptchaService;
import icu.d4peng.basic.captcha.service.impl.CaptchaServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * CaptchaAutoConfiguration:验证码服务自动配置
 *
 * @author d4peng <a href="d4peng@qq.com">d4peng@qq.com</a>
 * @since 2023.12.02
 */
@Configuration
@EnableConfigurationProperties({ CaptchaProperties.class })
@ConditionalOnClass({ Captcha.class })
@ConditionalOnProperty(prefix = CaptchaProperties.PREFIX, name = { "enabled" }, havingValue = "true",
		matchIfMissing = true)
public class CaptchaAutoConfiguration {

	private static final Logger LOGGER = LoggerFactory.getLogger(CaptchaAutoConfiguration.class);

	@Bean
	@ConditionalOnMissingBean({ CaptchaService.class })
	public CaptchaService captchaService(CaptchaProperties captchaProperties) {
		return new CaptchaServiceImpl(captchaProperties);
	}

}
